package test
{
	import away3d.cameras.Camera3D;
	import away3d.containers.Scene3D;
	import away3d.containers.View3D;
	import away3d.controllers.HoverController;
	import away3d.core.render.RendererBase;
	import away3d.debug.Trident;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Vector3D;
	
	public class DebugView extends View3D
	{
		private var hoverController:HoverController;
		private var _prevMouseX:Number;
		private var _prevMouseY:Number;
		private var _isRightMouseDown:Boolean;
		
		public function DebugView(triLen:int=100, scene:Scene3D=null, camera:Camera3D=null, renderer:RendererBase=null, forceSoftware:Boolean=false)
		{
			super(scene, camera, renderer, forceSoftware);
			
			var axis:Trident = new Trident(triLen,true);
			this.scene.addChild(axis);
			
			hoverController = new HoverController(this.camera, null, 50, 13, 400) ;
			
			addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown);
			addEventListener(MouseEvent.RIGHT_MOUSE_UP, onRightMouseUp);
			addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
			addEventListener(MouseEvent.MOUSE_MOVE, onRightMouseMove);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(event:Event):void
		{
			render();
		}
		
		private function onRightMouseDown(ev:MouseEvent):void
		{
			_prevMouseX = ev.stageX;
			_prevMouseY = ev.stageY;
			_isRightMouseDown = true;
		}
		
		private function onRightMouseUp(ev:MouseEvent):void {
			_isRightMouseDown = false;
		}
		
		private function onRightMouseMove(ev:MouseEvent):void
		{
			if (_isRightMouseDown) {
				hoverController.panAngle += (ev.stageX - _prevMouseX);
				hoverController.tiltAngle += (ev.stageY - _prevMouseY);
			}
			
			_prevMouseX = ev.stageX;
			_prevMouseY = ev.stageY;
		}
		
		private function onMouseWheel(ev:MouseEvent):void
		{
			hoverController.distance -= ev.delta * 5;
			
			if (hoverController.distance < 100)
				hoverController.distance = 100;
			else if (hoverController.distance > 2000)
				hoverController.distance = 2000;
		}
	}
}